


#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>

#include <iostream>
#include <string>

/*
https://blog.csdn.net/weixin_44347020/article/details/132562039
https://blog.csdn.net/WNX10086/article/details/137167923
*/

static void test_case() {

    using namespace boost::property_tree;
    ptree pt;
    //read_json("../src/conf.json", pt);
    try {
        read_json("../src/conf.json", pt);
    } catch (json_parser_error ex) {
        std::cout << "can't find configxx.json : " << ex.what();
        exit(0);
    }

    std::cout << "conf count << " << pt.count("conf") << std::endl;
    std::cout << "conf.theme count << " << pt.get_child("conf").count("theme") << std::endl;

    std::cout << pt.get<std::string>("conf.theme") << std::endl;
    std::cout << pt.get<int>("conf.clock_style") << std::endl;
    std::cout << pt.get<long>("conf.gui") << std::endl;
    std::cout << pt.get("conf.no_prop", 100) << std::endl;
    pt.put("conf.new_property", 1000);

    for (auto x : pt.get_child("conf.urls"))
        std::cout << x.second.data() << ", " ;    

    boost::property_tree::write_json("config.json", pt);


}

/*
valgrind --tool=memcheck --leak-check=full  ./bin/test_json
*/

int main() {

    for (int i = 0; i < 1000; i++)
        test_case();
    return 0;   
}